package exception

import (
	"xincan.com.cn/tarot-go/internal/common/constants"
	"xincan.com.cn/tarot-go/internal/common/exception"
)

// 错误码: 定义验证器错误码信息
var (
	ErrValidationNotFound     = constants.NewCodeStatus(5000, "验证器不存在")
	ErrCreateValidationFailed = constants.NewCodeStatus(5001, "创建验证器失败")
	ErrSearchValidationFailed = constants.NewCodeStatus(5002, "查询验证器失败")
)

// ValidationException
// Title    		ValidationException
// Description   	验证器异常信息结构体
// Author      		alittlexincan@163.com         						2024/07/22 11:36
// Update      		alittlexincan@163.com         						2024/07/22 11:36
type ValidationException struct {
	// 业务异常信息: 注入业务异常信息结构体
	*exception.BusinessException
}

// ValidationExceptionBuilder
// Title    		NewValidationException
// Description   	创建验证器异常信息结构体
// Author      		alittlexincan@163.com         						2024/07/22 11:36
// Update      		alittlexincan@163.com         						2024/07/22 11:36
// Param    		err 				*exception.RuntimeException		验证器异常信息结构体
// Return 			*UserException										返回验证器异常信息结构体
func ValidationExceptionBuilder() *ValidationException {
	return &ValidationException{
		BusinessException: exception.BusinessExceptionBuilder().WithModel("验证码管理"),
	}
}

//	Error
//
// Title    		Error
// Description   	实现并重写语言内置的error
// Author      		alittlexincan@163.com         						2024/07/22 11:36
// Update      		alittlexincan@163.com         						2024/07/22 11:36
func (validate *ValidationException) Error() string {
	return validate.BusinessException.Error()
}

func (validate *ValidationException) WithError(cs *constants.CodeStatus, err error) *ValidationException {
	_ = validate.BusinessException.WithCode(cs.Code()).WithMessage(cs.Message()).WithError(err)
	return validate
}
